<?php

/**
 * Flickr Photosets - Configuration Page
 * Allows the user to set their configuration.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets
*/
$fp = new FlickrPhotosetsConfig();

?>

<script src="<?=$fp->callback_url?>/scripts/common.js?<?=trim(REVISION)?>" type="text/javascript"></script>
<script src="<?=$fp->callback_url?>/scripts/configure.js?<?=trim(REVISION)?>" type="text/javascript"></script>

<fb:title>Configuration</fb:title>
<?=$fp->get_stylesheet('configure')?>
<?=$fp->get_header('configure', $fp->application_name.' Configuration', true)?>

<?php
/*
Show the option to Authenticate if no information is present in the database
*/
if (!$fp->is_flickr_authorized()) { ?>
	
	<?=$fp->print_messages()?>
	
	<div class="boxes clearfix">
		<div class="left_column">
			
			<div class="box" id="account_box">
				<h3>Flickr Account</h3>
				<div class="inside">
					
					<p>Click on the Authenticate button below to setup your Flickr account. When you click Authenticate, you will be redirected to Flickr to authorize access.</p>
					
					<fb:dialog id="auth_dialog" cancel_button=1>
						<fb:dialog-title>Authenticate Flickr Account</fb:dialog-title>
						<fb:dialog-content>
							<h3>What permissions do you want to give to <?=$fp->application_name?>?</h3>
							<p><strong>Read permissions</strong> only allow <?=$fp->application_name?> to access your photos (including private photos).</p>
							<p><strong>Write permissions</strong> allow <?=$fp->application_name?> to access your photos, edit your photo information, and upload photos to your account.</p>
							<p>You will need to give <strong>Write</strong> permission in order to allow photo tagging.</p>
							<h3>If you are not sure which one to choose, click Read.</h3>
						</fb:dialog-content>
						<fb:dialog-button type="button" value="Read" href="<?=$fp->callback_url?>/auth.php" />
						<fb:dialog-button type="button" value="Write" href="<?=$fp->callback_url?>/auth.php?write" />
					</fb:dialog>
					
					<form action="<?=$fp->callback_url?>/auth.php?write">
						<div class="buttons">
							<input type="submit" class="button" value="Authenticate" />
						</div>
					</form>
					
				</div>
			</div>
			
		</div>
	</div>

<?php }
/*
Otherwise, show all of the configuration options
*/
else { ?>
	
	<?=$fp->print_messages()?>
	
	<div class="boxes clearfix">
		<div class="left_column">
			
			<div class="box" id="account_box">
				<h3>Flickr Account</h3>
				<div class="inside">
					
					<p style="font-size:12px;border:1px solid #e2c822;background-color:#fff9d7;padding:7px;"><strong>Your Facebook account is currently associated with <a href="<?=$fp->flickr->urls_getUserProfile($fp->nsid)?>"><?=$fp->flickr_user['username']?></a> and is authorized with <?=$fp->perms?> permissions.</strong></p>

					<p>Click on the Remove Account button below to remove your association with your Flickr account. Once you remove it, you can either add a different account, or the same one again.</p>

					<fb:dialog id="remove_dialog" cancel_button=1>
						<fb:dialog-title>Remove Flickr Account</fb:dialog-title>
						<fb:dialog-content>
							<h3>Are you sure you want to remove your Flickr account from <?=$fp->application_name?>?</h3>
							<p>This <strong>will not</strong> remove the application from your Facebook account. You will be given the opportunity to revoke the permissions on Flickr once your account information is removed from <?=$fp->application_name?>.</p>
						</fb:dialog-content>
						<fb:dialog-button type="button" value="Remove Flickr Account" href="<?=$fp->canvas_url?>/auth.php?remove" />
					</fb:dialog>
					
					<form>
						<div class="buttons">
							<input type="button" class="button" value="Remove Flickr Account" clicktoshowdialog="remove_dialog" />
						</div>
					</form>
					
					<?php
					// Show option to enable write permissions if they only have read
					/*if ($fp->config['flickr_auth'] == 'r') { ?>

						<p>You will need to give write permissions to <?=$fp->application_name?> if you want to enable photo tagging.</p>

						<fb:editor action="" labelwidth="0">
							<fb:editor-buttonset>
								<input type="button" class="editorkit_button action" value="Give Write Permissions" clicktoshowdialog="write_dialog" />
							</fb:editor-buttonset>

							<fb:dialog id="write_dialog" cancel_button=1>
								<fb:dialog-title>Give Write Permissions</fb:dialog-title>
								<fb:dialog-content>
									<h3>Do you want to give write permissions to <?=$fp->application_name?>?</h3>
									<p><strong>Write permissions</strong> allow <?=$fp->application_name?> to access your photos, edit your photo information, and upload photos to your account.</p>
									<p>You will need to give <strong>Write</strong> permission in order to allow photo tagging.</p>
								</fb:dialog-content>
								<fb:dialog-button type="button" value="Give Write Permissions" href="<?=$fp->callback_url?>/auth.php?write" />
							</fb:dialog>
						</fb:editor>

					<?php }*/ ?>
					
				</div>
			</div>
			
			<div class="box" id="privacy_box">
				<h3>Privacy</h3>
				<h4>Control what photos are shown and who can see them.</h4>
				<div class="inside">
					<fb:editor action="">

						<fb:editor-custom label="Photo Privacy">
							Show photos marked as 
							<select name="privacy_filter">
								<option value="<?=$fp->privacy_filter['public']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['public']) { echo ' selected'; } ?>>Public</option>
								<option value="<?=$fp->privacy_filter['friends']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends']) { echo ' selected'; } ?>>Friends</option>
								<option value="<?=$fp->privacy_filter['family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['family']) { echo ' selected'; } ?>>Family</option>
								<option value="<?=$fp->privacy_filter['friends_family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends_family']) { echo ' selected'; } ?>>Friends &amp; Family</option>
								<option value="<?=$fp->privacy_filter['private']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['private']) { echo ' selected'; } ?>>Private</option>
							</select>
							<br/><span class="editor-actions"><small>Public photos will always be shown, in addition to the selected privacy setting.</small></span>
						</fb:editor-custom>

						<fb:editor-custom label="Facebook Visibility">
							Show photos to
							<select name="privacy_visibility">
								<option value="<?=$fp->privacy_visibility['all']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['all']) { echo ' selected'; } ?>>Everyone</option>
								<option value="<?=$fp->privacy_visibility['friends']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['friends']) { echo ' selected'; } ?>>My Friends Only</option>
								<option value="<?=$fp->privacy_visibility['non-limited']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['non-limited']) { echo ' selected'; } ?>>My Friends (non-limited)</option>
							</select>
							<br/><span class="editor-actions"><small>Non-limited excludes anyone on your limited profile list.</small></span>
						</fb:editor-custom>

						<fb:editor-buttonset>
							<fb:editor-button name="fp_privacy" value="Set"/>
							<fb:editor-button name="fp_privacy" value="Reset"/>
							<fb:editor-cancel href="<?=$fp->canvas_url?>/configure.php" />
						</fb:editor-buttonset>

					</fb:editor>
				</div>
			</div>
			
			<div class="box" id="profile_box">
				<h3>Profile Box</h3>
				<h4>Control what your profile box looks like.</h4>
				<div class="inside">
					<fb:if-section-not-added section="profile">
						<p>It looks like you haven't added the profile box yet. Click the button below to add it, then come back here to configure it.</p>
						<fb:add-section-button section="profile" />
						<script type="text/javascript">
						document.getElementById('profile_box_options').setStyle('display', 'none');
						</script>
					</fb:if-section-not-added>
					<div id="profile_box_options">
						<form action="" method="post">
						<table class="editorkit" border="0" cellspacing="0" style="width:425px"><tr class="width_setter"><th style="width:75px"></th><td></td></tr>

							<tr><th class="detached_label"><label>Display:</label></th><td class="editorkit_row">
								<select name="profile_display" onchange="profilePageOptions(this);" onload="profilePageOptions(this);">
									<option value="<?=$fp->profile_display['last']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['last']) { echo ' selected'; } ?>>
										Most Recent Photos
									</option>
									<option value="<?=$fp->profile_display['recent']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['recent']) { echo ' selected'; } ?>>
										Fairly Recent Photos
									</option>
									<option value="<?=$fp->profile_display['random']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random']) { echo ' selected'; } ?>>
										Random Photos
									</option>
									<option value="<?=$fp->profile_display['sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['sets']) { echo ' selected'; } ?>>
										Sets
									</option>
									<option value="<?=$fp->profile_display['random_sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random_sets']) { echo ' selected'; } ?>>
										Random Sets
									</option>
									<option value="<?=$fp->profile_display['overview']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['overview']) { echo ' selected'; } ?>>
										Overview
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<?php $photos_string = ($fp->config['profile_display'] == $fp->profile_display['sets']) ? 'Sets' : 'Photos' ; ?>
							<tr id="num_photos_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label id="profile_display_label">Number of <?=$photos_string?>:</label></th><td class="editorkit_row">

								<input type="text" onchange="checkNumPhotos(this);" value="<?=$fp->config['profile_count']?>" name="profile_count" id="profile_count_photos" maxlength="2" class="numphotos" />

								<span class="editor-actions"><small id="profile_display_small">Maximum 30 <?=strtolower($photos_string)?></small></span>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_tags_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tags (optional):</label></th><td class="editorkit_row">
								<input type="text" value="<?=$fp->config['profile_tags']?>" name="profile_tags" class="" />
								<span class="editor-actions"><small>Optional comma-separated list of tags</small></span>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_tagmode_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tag Mode:</label></th><td class="editorkit_row">
								<select name="profile_tagmode">
									<option value="<?=$fp->profile_tagmode['any']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['any']) { echo ' selected'; } ?>>
										ANY tag
									</option>
									<option value="<?=$fp->profile_tagmode['all']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['all']) { echo ' selected'; } ?>>
										ALL tags
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<tr id="profile_sortby_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Sort By:</label></th><td class="editorkit_row">
								<select name="profile_sort" id="profile_sort">
									<option value="<?=$fp->profile_sort['date_posted_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_desc']) { echo ' selected'; } ?>>
										Date Posted, Newest to Oldest
									</option>
									<option value="<?=$fp->profile_sort['date_posted_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_asc']) { echo ' selected'; } ?>>
										Date Posted, Oldest to Newest
									</option>
									<option value="<?=$fp->profile_sort['date_taken_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_desc']) { echo ' selected'; } ?>>
										Date Taken, Newest to Oldest
									</option>
									<option value="<?=$fp->profile_sort['date_taken_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_asc']) { echo ' selected'; } ?>>
										Date Taken, Oldest to Newest
									</option>
									<option value="<?=$fp->profile_sort['interesting_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_desc']) { echo ' selected'; } ?>>
										Interestingness, Most to Least
									</option>
									<option value="<?=$fp->profile_sort['interesting_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_asc']) { echo ' selected'; } ?>>
										Interestingness, Least to Most
									</option>
								</select>
							</td><td class="right_padding"></td></tr>

							<tr><th></th><td class="editorkit_buttonset">
								<input type="submit" class="editorkit_button action" value="Set" name="fp_profile" />
								<input type="submit" class="editorkit_button action" value="Reset" name="fp_profile" />
								<input type="submit" class="editorkit_button action" name="fp_profile" value="Preview" clickrewriteurl="<?=$fp->callback_url?>/profile.php?handle=<?=$fp->uid?>&amp;preview" clickrewriteid="profilepreview" clicktoshow="profilepreview"/>
								<span class="cancel_link"><span>or</span><a href="<?=$fp->canvas_url?>/configure.php">Cancel</a></span>
							</td><td class="right_padding"></td></tr>

						</table></form>
						<div id="profilepreview" style="display:none;width:420px;margin:auto;"></div>
					</div>
				</div>
			</div>
			
		</div>
		<div class="right_column">
			
			<div class="box" id="features_box">
				<h3>Features</h3>
				<h4>Enable and disable application features.</h4>
				<div class="inside">
					<form action="" method="post">
						<? /* <label for="enable_newsfeed">
							<input type="checkbox" id="enable_newsfeed" name="enable_newsfeed" value="1" <?=($fp->config['enable_newsfeed']) ? 'checked ' : '' ?> /> News Feed Notifications
						</label>
						<label for="enable_tagging">
							<input type="checkbox" id="enable_tagging" name="enable_tagging" value="1" <?=($fp->config['enable_tagging']) ? 'checked ' : '' ?> <?=($fp->config['flickr_auth'] == 'r') ? 'disabled' : '' ?> /> Photo Tagging
						</label> */ ?>
						<label for="enable_comments">
							<input type="checkbox" id="enable_comments" name="enable_comments" value="1" <?=($fp->config['enable_comments']) ? 'checked="checked" ' : ' ' ?> /> Photo and Photoset Comments
						</label>
						<label for="enable_gallery_photostream">
							<input type="checkbox" id="enable_gallery_photostream" name="enable_gallery_photostream" value="1" <?=($fp->config['enable_gallery_photostream']) ? 'checked="checked" ' : ' '?>/> Photostream Page
						</label>
						<label for="enable_gallery_photosets">
							<input type="checkbox" id="enable_gallery_photosets" name="enable_gallery_photosets" value="1" <?=($fp->config['enable_gallery_photosets']) ? 'checked="checked" ' : ' '?>/> Photosets Page
						</label>
						<label for="enable_gallery_geotagged">
							<input type="checkbox" id="enable_gallery_geotagged" name="enable_gallery_geotagged" value="1" <?=($fp->config['enable_gallery_geotagged']) ? 'checked="checked" ' : ' '?>/> Geotagged Photos Page
						</label>
						
						<div class="buttons">
							<input type="submit" class="button" value="Set" name="fp_features" />
							<input type="submit" class="button" value="Reset" name="fp_features" />
							<span class="cancel_link">or<a href="<?=$fp->canvas_url?>/configure.php">Cancel</a></span>
						</div>
						
					</form>
				</div>
			</div>
			
			<fb:if-section-not-added section="info">
				<div class="box" id="add_info_box">
					<h3>Info Box</h3>
					<div class="inside">
						<fb:add-section-button section="info" />
					</div>
					<div class="clearfix"></div>
				</div>
			</fb:if-section-not-added>
			
			<div class="box" id="troubleshooting_box">
				<h3>Problems</h3>
				<h4>Try these if you're having problems.</h4>
				<div class="inside">
					<form>
						<p>If the profile box has disappeared from your profile or you are having issues with the profile box not updating properly or giving errors:</p>
						<div class="buttons">
							<input type="submit" class="button" name="fp_problems" value="Reset Profile Box" />
						</div>
					</form>
					<p style="margin: 20px 0 0;" class="info_message">If you're having any other problems, please <a href="http://www.facebook.com/board.php?uid=<?=$fp->app_properties['app_id']?>"><fb:intl desc="submit your question">submit your question to the discussion group</fb:intl></a>.</p>
				</div>
			</div>
			
			<div class="box" id="donate_box">
				<h3>Donate</h3>
				<div class="inside">
					<p>If you find this application really useful, please consider donating.</p>
					<form action="https://www.paypal.com/cgi-bin/webscr">
						<input type="hidden" name="cmd" value="_s-xclick">
						<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYAzNweDNwpc+OhyjUYC2gw3pq8AzQys8cIyqad/itmbapyDU9CAF/pfVJ2YviNJV9Jw/ptuSkHt8ta6fhSvTox/S8RQm76Km0WO+hHPABrhCc5xWC6lGTTdGmc3yWsEdNWw3npHu5s9y//QOlC75JWHOPgUfIaUZYVsjX7/IIbwPTELMAkGBSsOAwIaBQAwgcQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIPVN6TUJcTVWAgaDZPR1ZcvVV2ghrGrkNqktGk4rhVPiuRuTtPYUnpsHfsCt0q7/eaN4K6hg61PjxQGGRP6IX9RymNNSm22uLL8kSmavr99g786T17Os4nU4iXT75zIl7rZ0Q/+cUc4ccUK6g5qwFh1JMEpu2MkUXL8pXTLlcnbu90TepNzKaMzODirh4hpy+MQQ0i+BowzSmY0ol7h98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moBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDcwNjE5MDMyMjEzWjAjBgkqhkiG9w0BCQQxFgQU9i4cB0+kwtXsBZ2ElcYQGegVPPMwDQYJKoZIhvcNAQEBBQAEgYAF6ULg0e2v41yVkdwcgsiMmTsanOd7jhjLZe02PhfF9MXsazNWoy1SYYxuCMlIzC9+3SRcTIyTdIAwVDZQ6fA6CSKAhtwpM3tXZ8yQuG9rhoeoKKTQarUKFMSt9MII7ecWEt1BF8cLIyNhsp45rhikXOsy5fgvCt/lqZ5ICJIiRg==-----END PKCS7-----
						">
						<div class="buttons">
							<input type="submit" class="button" value="Make a Donation" name="submit" />
						</div>
					</form>
				</div>
			</div>
			
		</div>
	</div>

<?php } ?>

<?=$fp->get_disclaimer(true)?>
<?=$fp->get_analytics()?>